﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Globalization;
using System.Data.SqlClient;
using System.Configuration;

namespace SS
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //panelProducts.Visible = false;
            //panelSales.Visible = false;
            elementHost1.Visible = false;
            chart1.Visible = false;
        }

        public static string DBConnect = ConfigurationManager.ConnectionStrings["SS.Properties.Settings.SSZZConnectionString"].ToString();

        private void SalesReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //ChartArea SalesChart = new ChartArea();
            //a.Area3DStyle.Enable3D = true;
            //a.Name = "Product";
            //SalesChart.CursorX.Interval = 10;
            //SalesChart.CursorY.Interval = 0.5;
            //SalesChart.Name = "HS";
            //SalesChart.Area3DStyle.Enable3D = true;  
            
            //GetSalesInfo();
            WPFusercontrol.Report_WPF ReportWPF = new WPFusercontrol.Report_WPF();
            elementHost1.Child = ReportWPF;
            elementHost1.Visible = true;
        }

        public void GetSalesInfo()
        {
            SqlConnection cn = new SqlConnection(DBConnect);
            
            SqlCommand cmd = cn.CreateCommand();

            //cmd.CommandText = "SELECT CategoryName, COUNT(*) as ProductCount FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID GROUP BY CategoryName ORDER BY CategoryName";
            cmd.CommandText = "select P.ProductName AS ProductName, sum(S.SalesAmout * UnitPrice) AS SalesAmout from Products P, Sales S WHERE P.productid= S.productid  GROUP BY P.ProductName";
            cn.Open();


            SqlDataReader dr = cmd.ExecuteReader();

            chart1.DataBindTable(dr, "ProductName");
            //chart1.Series[0].Name="HS";

            dr.Close();

            cn.Close();  
        }

        private void AddProductToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //panelProducts.Visible = true;
            //panelProducts.MaximumSize = Main.ActiveForm.Size;
            //panelSales.Visible = false;

            WPFusercontrol.Product product = new WPFusercontrol.Product();
            elementHost1.Child = product;
            elementHost1.Visible = true;

        }

        private void AddSalesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //panelProducts.Visible = false;
            //panelSales.Show();
            //panelSales.Visible = true;
            WPFusercontrol.Sale sales = new WPFusercontrol.Sale();
            elementHost1.Child = sales;
            elementHost1.Visible = true;
        }

        private void SearchInventoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WPFusercontrol.Inventory inventory = new WPFusercontrol.Inventory();
            elementHost1.Child = inventory;
            elementHost1.Visible = true;
        }

        private void AddCustomersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WPFusercontrol.Customer customer = new WPFusercontrol.Customer();
            elementHost1.Child = customer;
            elementHost1.Visible = true;
        }
    }
}
